package com.perye.dokit.service.impl;

import com.perye.dokit.mapper.dao.DaoSupport;
import com.perye.dokit.service.WeddingTypeService;
import com.perye.dokit.utils.DateUtils;
import com.perye.dokit.utils.UuidUtil;
import com.perye.dokit.utils.ValidationUtil;
import com.perye.dokit.utils.pageData.PageData;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName WeddingTypeServiceImpl
 * @Description 婚礼类型类
 * @Date 2022/3/14 11:01
 * @Version 1.0
 **/
@Service
public class WeddingTypeServiceImpl implements WeddingTypeService {

    @Resource(name = "daoSupport")
    private DaoSupport dao;

    @Override
    public List<PageData> queryWeddingTypeList(PageData pageData) throws Exception {
        return (List<PageData>) dao.findForList("WeddingTypeMapper.queryWeddingTypeList", pageData);
    }

    @Override
    public int create(PageData pageData) throws Exception {
        String uid = UuidUtil.get32UUID();
        pageData.put("id", uid);
        pageData.put("isDelete", 0);
        pageData.put("createTime", DateUtils.getTime());
        pageData.put("updateTime", DateUtils.getTime());

        PageData imgInfo = new PageData();
        imgInfo.put("id", pageData.getString("imageId"));
        imgInfo.put("relationId", uid);

        dao.save("WeddingTypeMapper.insertWeddingType", pageData);

        return (int) dao.save("WeddingTypeMapper.updateWeVideoPicture", imgInfo);
    }

    @Override
    public void deleteAll(String[] ids) throws Exception {
        try {
            //软删除实际是更新
            List<String> idList = new ArrayList<>(Arrays.asList(ids));
            dao.delete("WeddingTypeMapper.deleteAll", idList);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void update(PageData pageData) throws Exception {
        PageData imgInfo = new PageData();
        imgInfo.put("id", pageData.getString("imageId"));
        imgInfo.put("relationId", pageData.getString("id"));

        dao.save("WeddingTypeMapper.updateWeVideoPicture", imgInfo);
        dao.update("WeddingTypeMapper.updateWeddingTypeInfo", pageData);
    }

    @Override
    public void updateIsOpenState(PageData pageData) throws Exception {
        dao.update("WeddingTypeMapper.updateWeddingTypeInfo", pageData);
    }
}
